package com.study.reactor.service.impl;

import com.google.common.collect.Lists;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

/**
 * @author Cliff
 * 时间：2022/8/29
 * 描述：
 */
public abstract class AbstractArWriteOff {


    /**
     * 核销白名称
     * update 是否修改源数据
     */
    protected List<String> writeOffWhitelist(List<String> sourceCustomerNo, Boolean update) {
        if (CollectionUtils.isEmpty(sourceCustomerNo)) {
            return Lists.newArrayList();
        }
        List<String> whitelist = new ArrayList<>();
        if (CollectionUtils.isEmpty(whitelist)) {
            return sourceCustomerNo;
        }
        if (Objects.equals(Boolean.TRUE, update)) {
            Iterator<String> iterator = sourceCustomerNo.iterator();
            while (iterator.hasNext()) {
                String s = iterator.next();
                if (whitelist.contains(s)) {
                    iterator.remove();
                }
            }
            return sourceCustomerNo;
        } else {
            List<String> result = new ArrayList<>(sourceCustomerNo.size());
            for (String s : sourceCustomerNo) {
                if (!whitelist.contains(s)) {
                    result.add(s);
                }
            }
            return result;
        }
    }

    /**
     *
     * @param sourceCustomerNo
     * @return
     * 不等于空表示不属于白名单之类
     * true 不是黑名单
     * false: 黑名单
     */
    protected boolean writeOffWhitelist(String sourceCustomerNo) {
        List<String> whitelist = new ArrayList<>();
        if (CollectionUtils.isEmpty(whitelist)) {
            return true;
        }
        if (whitelist.contains(sourceCustomerNo)) {
            return false;
        }
        return true;
    }

}
